import { useReactive } from "ahooks";
import { useModel } from "umi";
import compress from "gql-compress";

const useUpdateStaffPosition = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        loading: false,
    });

    const updateStaffPosition = async (values, callback) => {
        console.log(values);
        state.loading = true;
        let variables = {
            osUuid: values.osUuid,
            opUuid: values.opUuid || null,
        };
        let res = await graphqlFetch({
            query,
            variables,
        });
        callback && callback(res);
        state.loading = false;
    };

    return { ...state, updateStaffPosition };
};

let query = compress(`mutation MyMutation(
    $osUuid: UUID!
    $opUuid: UUID
  ) {
    updateOrganizationStaffByOsUuid(
        input: {
            osUuid: $osUuid
            organizationStaffPatch: {
                opUuid: $opUuid
            }
        }
    ) {
        clientMutationId
    }
}`);

export default useUpdateStaffPosition;
